/*******************************************************************************
*  file    : filedataprovider.hpp
*  created : 14.07.2014
*  author  : Slyshyk Oleksiy (alexSlyshyk@gmail.com)
*******************************************************************************/

#ifndef FILEDATAPROVIDER_HPP
#define FILEDATAPROVIDER_HPP

#include "dataprovider.hpp"

#include <QMap>
#include <QDateTime>
#include <QFileInfo>
#include <QSharedPointer>
#include <QFileSystemWatcher>

class  ReadFileFormatInterface;
class  SaveLoadObjectInterface;

class FileDataProvider : public DataProvider
{
    Q_OBJECT
public:
    explicit FileDataProvider(QObject *parent = 0);
    QString  name() const;

    void setFormatPlugins(const QSharedPointer<QMap<QString, ReadFileFormatInterface*>>& plugins);
    void setObjectPlugins(const QSharedPointer<QMap<QString, SaveLoadObjectInterface*>>& plugins);

    QSharedPointer<DataObject> loadDataObject(const QString   &file_name);
    QSharedPointer<DataObject> loadDataObject(const QFileInfo &file_info);
public:
    static int filesQuantity(const QString& dir_name);
public slots:
    void     setWatcherPath   ( const QString & path);
    void     processExistFiles( const QString & path );
public:
    QString  path() const;
private slots:
    void onDirectoryChanged ( const QString & path );
private:
    QSharedPointer<QMap<QString, ReadFileFormatInterface*>> formatPlugins_;
    QSharedPointer<QMap<QString, SaveLoadObjectInterface*>> saveLoadObjectPlugins_;

    QFileSystemWatcher*                     watcher_;
    QDateTime                               lastProcessedDate_;
    int                                     count_ = 0;
    bool                                    process_exist_ = true;
};

#endif // FILEDATAPROVIDER_HPP
